package gui.swings;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class JButtonDemo extends Applet {

	JButton btn1 = new JButton("JButton 1");
	JButton btn2 = new JButton("JButton 2");

	JTextField tf = new JTextField(20);

	public void init() {
		ActionListener al = new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				String name = ((JButton) e.getSource()).getText();
				tf.setText(name + "Pressed");
			}

		};
		this.btn1.addActionListener(al);
		this.btn2.addActionListener(al);

		this.add(this.btn2);
		this.add(this.btn1);
		this.add(this.tf);
	}

	public static void main(String[] args) {
		JButtonDemo applet = new JButtonDemo();
		JFrame frame = new JFrame("TextAreaNew");
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		frame.getContentPane().add(applet,BorderLayout.CENTER);
		frame.setSize(300,100);
		applet.init();
		applet.start();
		frame.setVisible(true);
	}
}
